<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>多数元素</title>
</head>
<body>
  <script>
    function fn(nums) {
      const cnt = new Map();
      for (let i = 0; i < nums.length; i++) {
        if (cnt.has(nums[i])) {
          cnt.set(nums[i], cnt.get(nums[i]) + 1);
        } else {
          cnt.set(nums[i], 1);
        }
      }
      const ans = [];
      for (const x of cnt.keys()) {
        if (cnt.get(x) > Math.floor(nums.length / 3)) {
          ans.push(x);
        }
      }
      return ans
    }
    console.log(fn([3, 2, 3]))
  </script>
</body>
</html>